package com.cms.admin.core.listener;

 
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

 



























import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
 
import org.springframework.web.context.support.WebApplicationContextUtils;
 
   
import com.cms.admin.model.City;
import com.cms.admin.model.FuncList;
 
import com.cms.admin.service.common.FuncListService;
 
import com.cms.admin.service.privilege.CityService;
import com.cms.admin.service.privilege.UserListService;
import com.cms.admin.util.PropertiesUtil;
 

/**
 * Application Lifecycle Listener implementation class ContextLoaderListenerHelper
 *
 */

public class ContextLoaderListenerHelper extends ContextLoaderListener   {
       
   private static Log log = LogFactory.getLog(ContextLoaderListenerHelper.class);   
   private CityService orgService ;
   private FuncListService menuService;
   private UserListService userService ;
   
   private ArrayList<City> orgList;
   private  List<FuncList>  menuList;
     static Map<String,String> OSMap= new HashMap<String,String>();
     static Map<String,String> pathMap= new HashMap<String,String>();
   
 
   
   
   private ServletContext  context=null;
   private String tag4ZTreeStart="[";
   private String tag4ZTreeEnd="]";
   
   private String orgList4ZTree=null;
   private String orgList4ZTreeData="";
   private String menuList4ZTree=null;
   private String menuList4ZTreeData="";
    
 
   /**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent event) {
    	 super.contextInitialized(event);
    	 System.out.print("ContextLoaderListenerHelper");

         ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());  

         //��ȡbean  

         orgService = (CityService) applicationContext.getBean("cityService");
         menuService= (FuncListService)applicationContext.getBean("funcListService");
         userService= (UserListService)applicationContext.getBean("userListService");
         
         context = event.getServletContext();
         
         
         log.info("������Ϣ:" +context.getServerInfo());
         log.info("��������:" +context.getServletContextName());
        
       
        
         getMenu4ZTree();
         context.setAttribute("menuList4ZTree", menuList4ZTree);
         getOrganization4ZTree();
         context.setAttribute("orgList4ZTree", orgList4ZTree);
         getOSInfo();
         context.setAttribute("OSMap", OSMap);
         
         String   file_real_path=context.getRealPath("/");  
    	 
		 log.info("ϵͳ��·��:" +file_real_path);
	     
		if (OSMap.get("os.name").toString().contains("Windows"))
		{

			 pathMap= PropertiesUtil.createConfig_Upload_Map();
			 
			 
								
		}
		else if (OSMap.get("os.name").toString().contains("Linux") || OSMap.get("os.name").toString().contains("linux")|| OSMap.get("os.name").toString().contains("Unix")||OSMap.get("os.name").toString().contains("unix")) 
		{
					
			 pathMap= PropertiesUtil.createConfig_Upload_Map();
		 
		}
		 
		 
          
		
		 log.info("pathMap:" +pathMap.toString());
		   context.setAttribute("pathMap", pathMap);
	      initUserInfo();
	      
	      
	    
			
			 
			 
    }

    /**
     * ��ʼ�����û�����
     */
    public void initUserInfo()
    { 
    	
    	 
    	
    }

    
    
    /**
     * Ϊ��ʼ���˵�tree׼��
     */
    public void getMenu4ZTree() { }
    
    
    
    /**
     * ������֯����
     */
	public void getOrganization4ZTree() { }
 
  
	/**
	 * ��ȡϵͳ���Լ�
	 *  
	 * @return
	 */
	public void getOSInfo()
	{
		
		
		
		 Properties props=System.getProperties(); //���ϵͳ���Լ�
		 
		 
		 //����ϵͳ����   
		 OSMap.put("os.name", props.getProperty("os.name"));
		 //����ϵͳ����   
		 OSMap.put("os.arch", props.getProperty("os.arch"));
		 //����ϵͳ�汾  
		 OSMap.put("os.version", props.getProperty("os.version"));
		 //Java ����ʱ�����汾 
		 OSMap.put("java.version", props.getProperty("java.version"));
		  
		// java.vendor Java ����ʱ������Ӧ��
		 OSMap.put("java.vendor", props.getProperty("java.vendor"));
		 // Java ��Ӧ�̵� URL 
		 OSMap.put("java.vendor.url", props.getProperty("java.vendor.url"));
		//  Java ��װĿ¼ 
		 OSMap.put("java.home", props.getProperty("java.home"));
		  //Java ������淶�汾 
		 OSMap.put("java.vm.specification.version", props.getProperty("java.vm.specification.version"));
		//  Java ������淶��Ӧ�� 
		 OSMap.put("java.vm.specification.vendor", props.getProperty("java.vm.specification.vendor"));
		 // Java ������淶���� 
		 OSMap.put("java.vm.specification.name", props.getProperty("java.vm.specification.name"));
		  //Java �����ʵ�ְ汾 
		 OSMap.put("java.vm.version", props.getProperty("java.vm.version"));
		  //Java �����ʵ�ֹ�Ӧ�� 
		 OSMap.put("java.vm.vendor", props.getProperty("java.vm.vendor"));
		 // Java �����ʵ������ 
		 OSMap.put("java.vm.name", props.getProperty("java.vm.name"));
		  //Java ����ʱ�����淶�汾 
		 OSMap.put("java.specification.version", props.getProperty("java.specification.version"));
		  //Java ����ʱ�����淶��Ӧ�� 
		 OSMap.put("java.specification.vendor", props.getProperty("java.specification.vendor"));
		  //Java ����ʱ�����淶���� 
		 OSMap.put("java.specification.name", props.getProperty("java.specification.name"));
		 // Java ���ʽ�汾�� 
		 OSMap.put("java.class.version", props.getProperty("java.class.version"));
		  //Java ��·�� 
		 OSMap.put("java.class.path", props.getProperty("java.class.path"));
		//  ���ؿ�ʱ������·���б�
		 OSMap.put("java.library.path", props.getProperty("java.library.path"));
		 // Ĭ�ϵ���ʱ�ļ�·�� 
		 OSMap.put("java.io.tmpdir", props.getProperty("java.io.tmpdir"));
		  //Ҫʹ�õ� JIT ������������ 
		 OSMap.put("java.compiler", props.getProperty("java.compiler"));
		 
		 //һ��������չĿ¼��·�� 
		 OSMap.put("java.ext.dirs", props.getProperty("java.ext.dirs"));
	 
		 
		 //�ļ��ָ������� UNIX ϵͳ���ǡ�/���� 
		 OSMap.put("jfile.separator ", props.getProperty("file.separator "));
		 
		 //·���ָ������� UNIX ϵͳ���ǡ�:���� 
		 OSMap.put("path.separator", props.getProperty("path.separator"));
		 
		 //�зָ������� UNIX ϵͳ���ǡ�/n���� 
		 OSMap.put("line.separator ", props.getProperty("line.separator "));
		 
		 //�û����˻����� 
		 OSMap.put("user.name ", props.getProperty("user.name "));
		 // �û�����Ŀ¼ 
		 OSMap.put("user.home", props.getProperty("user.home"));
		//  �û��ĵ�ǰ����Ŀ¼ 
		 OSMap.put("user.dir", props.getProperty("user.dir"));

		
		 
 
	 
		
		
	}

	 
	
	
 
}
